<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%news}}".
 *
 * @property integer $id
 * @property integer $catid
 * @property string $title
 * @property string $image
 * @property string $keywords
 * @property string $description
 * @property string $content
 * @property integer $listorder
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $deleted
 * @property string $source
 * @property integer $click_num
 *
 * @property Category $cat
 */
class News extends \common\models\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%news}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['catid', 'title', 'content', 'created_at', 'updated_at'], 'required'],
            [['catid', 'listorder', 'created_at', 'updated_at', 'deleted', 'click_num'], 'integer'],
            [['content'], 'string'],
            [['title', 'image', 'keywords'], 'string', 'max' => 128],
            [['description'], 'string', 'max' => 1024],
            [['source'], 'string', 'max' => 255],
            [['catid'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['catid' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'catid' => '文章分类',
            'title' => '标题',
            'image' => '图片',
            'keywords' => '关键字',
            'description' => '描述',
            'content' => '内容',
            'listorder' => '排序id',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted' => '标记删除',
            'source' => '来源',
            'click_num' => '点击数',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCat()
    {
        return $this->hasOne(Category::className(), ['id' => 'catid']);
    }
}
